<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>模板</title>
</head>

<body>
  <div id="app">
    <router-link to="/login">登录</router-link>
    <router-link to="/register">注册</router-link>
    <hr>
    <router-view></router-view>
  </div>
  <script src="../js/vue.js"></script>
  <script src="../js/vue-router.js"></script>
  <script>


    // 定义组件
    let Welcome = {
      template: `<div><h1>欢迎使用本系统</h1></div>`
    }
    let Login = {
      template: `<div><h2>我是登录组件</h2></div>`
    }
    let Register = {
      template: `<div><h1>我是注册组件</h1></div>`
    }

    // 定义路由列表
    let routes = [
      // 方式一:不推荐
      /*       {
              path: '/',
              component: Welcome
            }, */
      {
        path: '/',
        // 方式二 重定向:路径会发生改变
        // redirect: '/login'
        // 方式三
        // redirect: {name: 'login'}
        // 方式四
        redirect: {
          path: '/login'
        }
      },
      {
        path: '/login',
        name: 'login',
        component: Login
      },
      {
        path: '/register',
        component: Register
      },
      {
        path: '/welcome',
        alias: '/uu', //别名
        component: Welcome
      }
    ]

    // 定义路由器
    let router = new VueRouter({
      routes
    })

    // 创建Vue实例
    let vm = new Vue({
      el: '#app',
      data: {

      },
      router //绑定路由器
    })
  </script>
</body>

</html>